var dbConfig = require("../utils/dbconfig");
var express = require("express");
var Response = require("../utils/response");

function findMenuByUserId(req, res, next) {
  // // let token = req.headers.token;
  // // if (!token) res.send({ data: "用户未登录，请先登录", code: 0 });
  // let { username, password } = req.query;
  // // let username = "admin",
  // //   password = "123456";
  // let userid = 1;
  let { id } = req.query;
  var sql = `SELECT pr.* FROM staff_sys.base_user u LEFT JOIN staff_sys.base_user_role ur ON ur.user_id = u.id LEFT JOIN staff_sys.base_role_privilege p ON p.role_id=ur.role_id LEFT JOIN staff_sys.base_privilege pr ON pr.id=p.privilege_id WHERE u.id=?`;
  var sqlArr = [id];
  var callBack = (err, data) => {
    if (err) {
      console.log("连接出错了");
    } else {
      if (data.length > 0) {
        res.send(new Response(200, "查询成功", data));
      } else {
        res.send(new Response(500, "查询失败", data));
      }
    }
  };

  dbConfig.sqlConnection(sql, sqlArr, callBack);
}

module.exports = {
  findMenuByUserId,
};
